<?php
/**
 * 
 * 猜你喜欢信息
 * xysc users Version1.0
 * ==================================
 * Copy 2016-2017
 * Web:www.xjh7.com
 * ==================================
 * Author:xjh
 * Date:2016-5-02
 * model() 创建模型对象，静态
 * tableName() 返回表名
*/

class Record extends CActiveRecord{
	/**
	 *返回当前模型对象的方法 
	 */
	public static function model($className = __CLASS__){
		return parent::model($className);
	}
	
	/**
	 * 返回当前表名
	 */
	public function tableName(){
		return '{{record}}';
	}
	
	
	//存入最近浏览的信息
	public function setRecord($user_id,$goods_id){
		$cmodel = new CCCModel();
		$_sql = "SELECT record_id FROM {{record}} WHERE user_id = $user_id AND goods_id = $goods_id";
		$infos = $cmodel -> sel($_sql);
		if(empty($infos)){
			$_sql = "INSERT INTO {{record}}(
								`user_id`,
								`goods_id`,
								`record_time`
							) VALUES(
								$user_id,
								$goods_id,
								NOW()
							)";
		}else{
			$_sql = "UPDATE {{record}} SET record_time=NOW() WHERE user_id = $user_id AND goods_id = $goods_id";
		}
		$row = $cmodel->upd($_sql);
		return $row;
	}
	
	
	//读取最近浏览的信息(展示到猜你喜欢)
	public function getRecord($user_id){
		$all_model = new CCCModel();
		$_sql = "SELECT a.goods_price,a.goods_id,a.goods_name,a.goods_thumbnail_url FROM {{goods}} a,{{record}} b WHERE a.goods_id = b.goods_id AND b.user_id=$user_id ORDER BY record_time DESC LIMIT 0,5";
		$result = $all_model->sel($_sql);
		return $result;
	}

}
	
?>